<template>
	<view class="flex-col homepage" v-model="adds">
		<view class="flex-row wrapper" @click="ListAll()">
			<view class="u-line-1 text">报修房屋</view>
			<view class="u-line-1 text-two">{{adds1.address}}</view>
		</view>
		<view class="flex-row wrapper-two">
			<view class="u-line-1 text-three">维修项目</view>
			<u-picker :show="show" ref="uPicker" @cancel="show=false" :columns="columns" @confirm="confirm"
				@change="changeHandler"></u-picker>
			<view class="u-line-1 text-four" @click="show=true">
				<input v-model="adds.theProjectName" placeholder="请输入">
			</view>
			<view class="wraper-col">></view>
		</view>
		<view class="flex-row wrapper-three">
			<view class="u-line-1 text-five">标题</view>
			<input class="input" placeholder="请输入" v-model="adds.theTitle">
		</view>
		<view class="flex-col wrapper-four">
			<view class="u-line-1 text-six">问题描述</view>
			<input class="input1" placeholder="请输入" v-model="adds.problemDescription">
		</view>
		<view class="flex-row wrapper-five">
			<view class="u-line-1 text-seven">手机号码</view>
			<input class="input2" placeholder="请输入" v-model="adds.phone">
		</view>
		<view class="flex-row wrapper-six" @click="show1 = true">
			<view class="u-line-1 text-eight">预约日期</view>
			<uni-datetime-picker type="datetime" :border="false" v-model="adds.appointmentTime" />
		</view>
		
		<view class="tp">
			<u--text type="primary" text="上传损坏照片">上传本人身份证照片</u--text>
			<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="10">
			</u-upload>
		</view>
		
		<u-button class="button" @click="submit()">
			提交审核
		</u-button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				fileList1: [],
				datetimesingle: '',
				show1: false,
				mode: 'single',
				show: false,
				adds: {},
				adds1:{},
				columns: [
					['电器', '家居'],
					['冰箱', '水暖', '电源开关']
				],
				columnData: [
					['冰箱', '水暖', '电源开关'],
					['沙发', '地板', '桌子']
				]
			}
		},
		onLoad(params) {
			this.adds1 = JSON.parse(params.j)
		},
		methods: {
			submit() {
				this.adds.middleId=this.adds1.middleId
				this.adds.maintenanceProcess='审核中'
				this.$axios({
					url: 'serverwg/gwb/GwbAddTeance',
					data: this.adds,
					method: 'POST',
					success: (res) => {
						if (res.data.code === 20000) {
							uni.showModal({
								content: '添加成功,点击确认跳转页面',
								showCancel: false,
								success: (res) => {
									uni.navigateTo({
										url: '/pages/gwb/maintenance'
									})
								}
							});
						} else {
							uni.showModal({
								content: '添加失败,请将时间精确到小时或因为图片过大请更换图片',
								showCancel: false,
							});
						}
					}
				})
			},
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				this.user = uni.getStorageSync('user')
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://127.0.0.1:9000/serverwg/gwb/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test',
						},
						success: (res) => {
							if (res.data != null) {
								this.adds.url=res.data
							} else {
								alert("网络原因，上传失败")
							}
						}
					});
				})
			},
			ListAll() {
				uni.navigateTo({
					url: '/pages/gwb/AddmainList'
				})
			},
			
			confirm1(e) {
				this.adds.appointmentTime = e[0]
				this.show1 = false
			},
			changeHandler(e) {
				const {
					columnIndex,
					value,
					values,
					index,
					picker = this.$refs.uPicker
				} = e
				if (columnIndex === 0) {
					picker.setColumnValues(1, this.columnData[index])
				}
			},
			confirm(e) {
				this.adds.theProjectName = e.value[1]
				this.show = false
			},
		}
	}
</script>
<style lang="scss" scoped>
	/** 全局样式-开始,建议放在公共css样式文件中,比如common.css 或app.vue文件 */

	html,
	body {
		margin: 0;
		width: 100%;
		height: 100%;
		font-size: 16px
	}

	view,
	text,
	image {
		position: relative;
		box-sizing: border-box;
		flex-shrink: 0;
	}
	.tp{
		 margin-top: -230rpx;
	}
	.flex-col {
		display: flex;
		align-items: flex-start;
		flex-direction: column;
	}

	.flex-row {
		display: flex;
		align-items: flex-start;
	}

	.flex-col .flex-row {
		width: 100%
	}

	/** 全局样式-结束*/

	.homepage {
		height: 1334rpx;
		padding: 34rpx 32rpx 0rpx 32rpx;

		.wrapper {
			width: 674rpx;
			justify-content: space-between;
			margin-right: auto;
			margin-left: auto;
			padding: 36rpx 60rpx 36rpx 0rpx;
			border-bottom-width: 2rpx;
			border-bottom-style: solid;
			border-bottom-color: rgba(226, 226, 226, 1);

			.text {
				width: 166rpx;
				font-size: 30rpx;
				font-weight: 600;
				color: rgba(57, 61, 73, 1);
			}

			.text-two {
				width: 432rpx;
				font-size: 28rpx;
				font-weight: 600;
				color: rgba(130, 130, 130, 1);
			}
		}

		.wrapper-two {
			width: 674rpx;
			margin-right: auto;
			margin-left: auto;
			padding: 36rpx 0rpx;
			border-bottom-width: 2rpx;
			border-bottom-style: solid;
			border-bottom-color: rgba(226, 226, 226, 1);

			.text-three {
				width: 166rpx;
				margin-right: 14rpx;
				font-size: 30rpx;
				font-weight: 600;
				color: rgba(57, 61, 73, 1);
			}

			.text-four {
				width: 190rpx;
				margin-right: 272rpx;
				font-size: 28rpx;
				font-weight: 600;
				color: rgba(130, 130, 130, 1);
			}

			.wraper-col {
				width: 24rpx;
				height: 38rpx;
			}
		}

		.wrapper-three {
			width: 674rpx;
			justify-content: space-between;
			margin-right: auto;
			margin-left: auto;
			padding: 20rpx 80rpx 20rpx 0rpx;
			border-bottom-width: 2rpx;
			border-bottom-style: solid;
			border-bottom-color: rgba(226, 226, 226, 1);

			.text-five {
				width: 166rpx;
				margin-top: 16rpx;
				font-size: 30rpx;
				font-weight: 600;
				color: rgba(57, 61, 73, 1);
			}

			.input {
				width: 408rpx;
				border: none;
				color: rgba(130, 130, 130, 1);
				font-weight: 600;
				margin: 20rpx 0rpx 0rpx 10rpx;
			}
		}

		.wrapper-four {
			width: 674rpx;
			margin-right: auto;
			margin-left: auto;
			padding: 36rpx 0rpx 8rpx 0rpx;
			border-bottom-width: 2rpx;
			border-bottom-style: solid;
			border-bottom-color: rgba(226, 226, 226, 1);

			.text-six {
				width: 166rpx;
				margin-bottom: 26rpx;
				font-size: 30rpx;
				font-weight: 600;
				color: rgba(57, 61, 73, 1);
			}

			.input1 {
				width: 650rpx;
				height: 114rpx;
				margin-right: auto;
				margin-left: auto;
				border: none;
				font-weight: 600;
				color: rgba(130, 130, 130, 1);
			}

		}

		.wrapper-five {
			width: 674rpx;
			justify-content: space-between;
			margin-right: auto;
			margin-left: auto;
			padding: 20rpx 74rpx 20rpx 0rpx;
			border-bottom-width: 2rpx;
			border-bottom-style: solid;
			border-bottom-color: rgba(226, 226, 226, 1);

			.text-seven {
				width: 166rpx;
				margin-top: 16rpx;
				font-size: 30rpx;
				font-weight: 600;
				color: rgba(57, 61, 73, 1);
			}

			.input2 {
				width: 408rpx;
				border: none;
				color: rgba(130, 130, 130, 1);
				font-weight: 600;
				margin: 20rpx 0rpx 0rpx 10rpx;
			}
		}

		.wrapper-six {
			width: 674rpx;
			margin-right: auto;
			margin-bottom: 290rpx;
			margin-left: auto;
			padding: 20rpx 0rpx;
			border-bottom-width: 2rpx;
			border-bottom-style: solid;
			border-bottom-color: rgba(226, 226, 226, 1);

			.text-eight {
				width: 126rpx;
				margin: 16rpx 38rpx 0rpx 0rpx;
				font-size: 30rpx;
				font-weight: 600;
				color: rgba(57, 61, 73, 1);
			}

			.input3 {
				width: 448rpx;
				border: none;
				color: rgba(130, 130, 130, 1);
				font-weight: 600;
				margin: 15rpx 0rpx 0rpx 30rpx;
			}

			.wraper-col-two {
				width: 24rpx;
				height: 34rpx;
				margin-top: 18rpx;
			}
		}

		.button {
			width: 100%;
			height: 82rpx;
			font-size: 34rpx;
			background: rgba(21, 111, 255, 1);
			font-weight: 600;
			color: rgba(255, 255, 255, 1);
		}
	}
</style>
